import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
const store = new Vuex.Store({
    state: {
        localData: {
            phone: "",
            nickname: "",
            sex: "",
            description: "",
            loggedin: false,
            status: ""
        },
        hasLogin: false
    },
    mutations: {
        login(state, provider) { //改变登录状态  
            state.hasLogin = true
            state.localData.phone = provider.phone
            state.localData.nickname = provider.nickname
            state.localData.sex = provider.sex
            state.localData.description = provider.description
            state.localData.status = provider.status
            state.localData.loggedin = provider.loggedin = true;
            uni.setStorage({ //将用户信息保存在本地  
                key: 'localData',
                data: provider
            });
        },
        logout(state) { //退出登录  
            console.log("log out");
            state.hasLogin = false
            state.localData = {}
            uni.removeStorage({
                key: 'localData'
            })
        }
    }
})

export default store;